package escom.dds.gestionarreporte.dao;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

/**
 *
 * @author jorge
 */
public class BD {

    private Connection conexion;
    private String usuario, password, url, driver, bd;

    public BD() {
        this.usuario = "root";
        this.password = "root";
        this.bd = "modelo";
        this.url  = "jdbc:mysql://localhost/" + this.bd;
        this.driver = "com.mysql.jdbc.Driver";
    }

    public BD(String usuario, String password, String bd, String url, String driver) {
        this.usuario = usuario;
        this.password = password;
        this.bd = bd;
        this.url = url+this.bd;
        this.driver = driver;
    }

    public String getUsuario() {
        return usuario;
    }

    public String getPassword() {
        return password;
    }

    public String getUrl() {
        return url;
    }

    public String getDriver() {
        return driver;
    }

    public String getBd() {
        return bd;
    }

    /* 
     * Abrir conexion con la base de datos
     */
    public Connection abrirConexion() throws Exception {
        try {
        	System.out.println("en la clase bd");
            Class.forName("com.mysql.jdbc.Driver").newInstance();
            conexion = DriverManager.getConnection(url, usuario, password);
            if (conexion != null) {
                return conexion;
            }
            return null;
        } catch (Exception e) {
            throw e;
        }
    }

    /*
     * Cerrar conexion
     */
    public boolean cerrarConexion() {
        try {
            conexion.close();
            return true;
        } catch (SQLException ex) {
            return false;
        }
    }
    
}
